package billrestauration.entities;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.springframework.context.annotation.Lazy;
import org.springframework.web.multipart.MultipartFile;

@Entity
@Lazy(value=false)
@Table(name="menu")
public class Menu {
	public static final int TOUT=0x00;//"TOUT";
	public static final int DINER=0x03;//"DINER";
	public static final int PETIT_DEJEUNER=0x01;//"PETIT_DEJEUNER";
	public static final int DEJEUNER=0x02;//"DEJEUNER";
	 
	 
	@Column(nullable=false)
private String nom;
public Menu() {
		super();
		// TODO Auto-generated constructor stub
		this.disponible=true;
		this.periode=Menu.TOUT;
		this.estmenudujour=true;
		this.prix=new Prix();
	}
public synchronized void incQuantite(){
	this.quantite++;
	
}
public synchronized void decQuantite(){
	if(this.quantite>0)
	this.quantite--;
	if(this.quantite==0)
		this.setDisponible(false);
}
 
@Override
public String toString() {
	return "Menu [nom=" + nom + ", description=" + description
			+ ", disponible=" + disponible + ", estmenudujour=" + estmenudujour
			+ ", quantite=" + quantite + ", id=" + id + ", periode=" + periode
			+ ", image=" + image + ", prix=" + prix + "]";
}

public String getNom() {
		return nom;
	}
	public String getImage() {
	return image;
}

public void setImage(String image) {
	this.image = image;
}

	public void setNom(String nom) {
		this.nom = nom;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public boolean isDisponible() {
		return disponible;
	}
	public void setDisponible(boolean disponible) {
		this.disponible = disponible;
	}
	public boolean isEstmenudujour() {
		return estmenudujour;
	}
	public void setEstmenudujour(boolean estmenudujour) {
		this.estmenudujour = estmenudujour;
	}
	public int getQuantite() {
		return quantite;
	}
	public void setQuantite(int quantite) {
		this.quantite = quantite;
		if(this.quantite<0)
			this.quantite=0;
	}
	public int getPeriode() {
		return this.periode;
	}
	public String getPeriodestring() {
		if(0>periode) return "PETIT DEUJ, DEUJ, DINER";
		switch (periode) {
		case Menu.TOUT:
			
			return "PETIT DEUJ, DEUJ, DINER";

case Menu.DINER:
			
			return " DINER";

case Menu.PETIT_DEJEUNER:
	
	return "PETIT DEUJ ";

case Menu.DEJEUNER:
	
	return " DEUJ ";
default: return "PETIT DEUJ, DEUJ, DINER";
		}
		 
	}
	public void setPeriode(int periode) {
		this.periode = periode;
	}
	public Prix getPrix() {
		return prix;
	}
	public void setPrix(Prix prix) {
		this.prix = prix;
	}
@Column(nullable=true)
private String description;
@Column(nullable=false)
private boolean disponible;
@Column(nullable=false)
private boolean estmenudujour;
@Column(nullable=false)
private int quantite;
@Column
@Id
@GeneratedValue
private long id;
public Menu(String nom, String description, boolean disponible,
		boolean estmenudujour, int quantite, long id, int periode, Prix prix,String image) {
	super();
	this.nom = nom;
	this.description = description;
	this.disponible = disponible;
	this.estmenudujour = estmenudujour;
	this.quantite = quantite;
	this.id = id;
	this.periode = periode;
	this.prix = prix;
	this.image=image;
}

public long getId() {
	return id;
}

public void setId(long id) {
	this.id = id;
}
/**
 * <blockquote>PETIT_DEJEUNER|DEJEUNER|DINER|TOUT</blockquote>
 */
@Column
private int periode;
@Column
private String image;
@OneToOne(targetEntity=Prix.class)
@JoinColumn(name="prix_par_menu",nullable=false,referencedColumnName="id")
private Prix prix;

}
